package com.shujia.wyh.mr.zuoye;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyMoneyReducer extends Reducer<Text, LongWritable,Text, DoubleWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, DoubleWritable>.Context context) throws IOException, InterruptedException {
        //<"王五",[10,30,..]>
        long sum = 0;
        long count = 0;
        for (LongWritable value : values) {
            sum+=value.get();
            count++;
        }

        double avg = sum*1.0/count;
        context.write(key,new DoubleWritable(avg));
    }
}
